package router

import (
	"../api/login"
	"../db/cache"
	"../lib"
	"../router/middleware"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"time"
)

var routs *gin.Engine

func login_rout(name string) {
	rout := routs.Group(name)
	rout.GET("login", login.UserLogin)          // 学员登陆
	rout.GET("reg", login.UserReg)              // 学员注册
	rout.GET("sms", login.SendSms)              // 发送验证码
	rout.GET("p_list", login.ProIdList)         // 项目列表
	rout.POST("authorvideo", login.AuthorVideo) // 授权点播
	rout.GET("classbegins", login.ClassBegins)  //开课
	rout.GET("set", login.NumberTel)            //修改手机号
	rout.GET("get", login.NumberTelGet)         //修改手机号
	rout.POST("employList", login.EmployList)
}
func login_new_rout(name string) {
	rout := routs.Group(name)
	rout.GET("ck_phone", func(c *gin.Context) { lib.Service(c, &login.CkPhone{}) })            //  检查手机号时候已存在用户中 /loginnew/ck_phone
	rout.GET("qr_login_code", func(c *gin.Context) { lib.Service(c, &login.QRLoginCode{}) })   //  获取登陆二维码 /loginnew/qr_login_code
	rout.GET("qr_login_fresh", func(c *gin.Context) { lib.Service(c, &login.QRLoginFresh{}) }) //  刷新登陆码结果 /loginnew/qr_login_fresh
	rout.GET("qr_login_scan", func(c *gin.Context) { lib.Service(c, &login.QRLoginScan{}) })   //  扫描验证登陆码[MB] /loginnew/qr_login_scan

	rout.GET("login", func(c *gin.Context) { lib.Service(c, &login.Login{}) })            //  账号密码、手机号验证码登录 /loginnew/login
	rout.GET("forget_pass", func(c *gin.Context) { lib.Service(c, &login.ForgetPass{}) }) //  忘记密码 /loginnew/forget_pass

	rout.GET("p_list", func(c *gin.Context) { lib.Service(c, &login.ProIdNew{}) }) //  获取所有的项目 /loginnew/p_list

	rout.GET("to_push_msg", func(c *gin.Context) { lib.Service(c, &login.ToPushMsgReq{}) }) //  loginnew/to_push_msg 更改直播课次时间

}



func file_rout(name string) {
	rout := routs.Group(name)
	rout.Use(middleware.JWTAuth(cache.VerifyTokenMutex))
	rout.POST("user", login.PngUpl) //七牛单文件上传
}

func init() {
	routs = gin.Default()
	Init()
	routs.Use(cors.New(cors.Config{
		AllowOriginFunc:  func(origin string) bool { return true },
		AllowMethods:     []string{"OPTIONS", "GET", "POST", "PUT", "DELETE", "PATCH"},
		AllowHeaders:     []string{"Origin", "Content-Length", "Content-Type", "Authorization"},
		AllowCredentials: true,
		MaxAge:           12 * time.Hour,
	}))

	login_rout("login")
	login_new_rout("loginnew")
	file_rout("file")           // 文件

	routs.Run(Run.RunPort)

}
